#ifndef H_BLINN_PHONG_FRAG_INCLUDED
#define H_BLINN_PHONG_FRAG_INCLUDED

//#include "Packages/com.unity.render-piplines.core/ShaderLibrary/Common.hlsl"
//#include "Packages/com.unity.render-piplines.core/ShaderLibrary/SpaceTransform.hlsl"

#include "../ShaderLibrary/LightInput.hlsl"
#include "../ShaderLibrary/BlinnPhong.hlsl"

struct Attributes
{
    float4 posL : POSITION;
    float3 normalL : NORMAL;
    float2 texC : TEXCOORD0;
};

struct Varyings
{
    float4 posH : SV_POSITION;
    float3 normalW : NORMAL;
    float2 texC : TEXCOORD0;
    float3 posW : TEXCOORD1;
};

UNITY_DECLARE_TEX2D(_MainTex);

CBUFFER_START(UnityPerMaterial)
float _Shininess;
fixed4 _SpecularColor;
fixed4 _Color;
float4 _MainTex_ST;
CBUFFER_END

Varyings vert (Attributes IN)
{
    Varyings OUT;
    OUT.posW = mul(UNITY_MATRIX_M, IN.posL);
    OUT.posH = mul(UNITY_MATRIX_MVP, IN.posL);
    OUT.normalW = mul((float3x3)UNITY_MATRIX_M, IN.normalL);
    OUT.texC = IN.texC;
    return OUT;
}

half4 frag (Varyings IN) : SV_TARGET
{
    //定义几何数据
    BlinnPhongGeo geo;
    geo.normal = normalize(IN.normalW);
    geo.viewDir = normalize(_WorldSpaceCameraPos - IN.posW);
    geo.position = IN.posW;

    //定义渲染参数
    BlinnPhongProperty property;
    property.diffuseColor = UNITY_SAMPLE_TEX2D(_MainTex, IN.texC) * _Color;
    property.specularColor = _SpecularColor;
    property.shininess = _Shininess;

    return BlinnPhong(H_MainLightDirection, geo, property);// * H_MainLightColor;

}

#endif